package com.syqc.choose.team

import androidx.fragment.app.Fragment
import com.gyf.immersionbar.ktx.immersionBar
import com.syqc.adapter.IFragmentPAdapter
import com.syqc.comlib.base.BaseActivity
import com.syqc.comlib.custom.MRadioToolbar
import com.syqc.interfaces.SimplePageChangeListener
import com.syqc.monitor.R
import com.syqc.monitor.databinding.ActivityChooseCarBinding
import com.syqc.monitor.databinding.IncludeToolbarRadioBinding
import com.syqc.monitor.databinding.IncludeViewpagerMatchBinding

/**
 *@Author Jasper
 *@Time   2020/7/22
 *@Desc   选择车队
 */
class ChooseTeamActivity :
    BaseActivity<ActivityChooseCarBinding>(ActivityChooseCarBinding::inflate),
    SimplePageChangeListener {
    private lateinit var mViewPagerVB: IncludeViewpagerMatchBinding
    private lateinit var mToolBarVB: IncludeToolbarRadioBinding
    private var isMap: Boolean = false
    private var isChoose: Boolean = false
    private val fragments by lazy { mutableListOf<Fragment>() }

    override fun initView() {
        mViewPagerVB = IncludeViewpagerMatchBinding.bind(binding.root)
        mToolBarVB = IncludeToolbarRadioBinding.bind(binding.root)
        immersionBar { titleBar(mToolBarVB.mCarRadioBar) }
        initData()
        initToolbar()
        isMap = intent.getBooleanExtra("isMap", false)
        isChoose = intent.getBooleanExtra("isChoose", false)
    }

    override fun setListener() {

    }


    override fun onPageSelected(position: Int) {
        mToolBarVB.mCarRadioBar.setCheckTwo(position)
    }

    private fun initData() {
        fragments.add(ChooseTeamFragment())
        fragments.add(SearchTeamFragment())
        mViewPagerVB.mViewPager.adapter = IFragmentPAdapter(supportFragmentManager, fragments)
        mViewPagerVB.mViewPager.addOnPageChangeListener(this)
    }

    private fun initToolbar() {
        mToolBarVB.mCarRadioBar.setTitle(R.string.title_choose_team, R.string.title_search_team)
        mToolBarVB.mCarRadioBar.setCallBack(object : MRadioToolbar.IToolbarCallback {
            override fun startCallback() {
                mViewPagerVB.mViewPager.currentItem = 0
            }

            override fun centerCallback() {
            }

            override fun endCallback() {
                mViewPagerVB.mViewPager.currentItem = 1
            }

        })
    }
}